package com.yang.job.service;

import com.yang.job.dao.JobInfoDao;
import com.yang.job.pojo.JobInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

/****
 *  @Author: 无为
 *  @Data: 2021/8/29 14:26
 */
@Service
public class JobInfoServiceImpl implements JobInfoService {

    @Autowired
    private JobInfoDao jobInfoDao;

    @Override
    @Transactional
    public void save(JobInfo jobInfo) {
        //查询原有的数据
        JobInfo param = new JobInfo();
        param.setUrl(jobInfo.getUrl());
        param.setTime(jobInfo.getTime());

        //执行查询
        List<JobInfo> list = this.findJobInfo(param);

        //判断数据库中是否有已存在的数据
        if(list.size()==0){
            //如果查询为空，表示招聘信息数据不存在，或者已经更新了，需要新增或者更新数据库
            jobInfoDao.saveAndFlush(jobInfo);
        }

    }

    @Override
    public List<JobInfo> findJobInfo(JobInfo jobInfo) {

        //设置查询条件
        Example<JobInfo> example = Example.of(jobInfo);

        //执行查询
        List list = this.jobInfoDao.findAll(example);

        return list;
    }
}
